#include <bits/stdc++.h>

using namespace std;

/*
动态规划, 递推后一位,
dp[i] 表示第i+i个丑数
dp[i]=min(a*2,b*3,c*5)
*/
class Solution {
public:
    int nthUglyNumber(int n) {
        int dp[n+1];
        dp[0]=1;
        int a=0,b=0,c=0;
        for(int i=1;i<n;i++){
            int aa=dp[a]*2,bb=dp[b]*3,cc=dp[c]*5;
            if(aa==dp[i-1])aa=dp[++a]*2;
            if(bb==dp[i-1])bb=dp[++b]*3;
            if(cc==dp[i-1])cc=dp[++c]*5;
            
            dp[i]=min(aa,min(bb,cc));


            dp[i]==aa?a++:(dp[i]==bb?b++:c++);
        }
        return dp[n-1];
    }
};



int main(){
    freopen("out.txt","w+",stdout);
    Solution s;
    for(int i=1;i<=1690;i++){
        cout << s.nthUglyNumber(i)<<",";
    }
   


    return 0;
}